<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
		#allmap{width:100%;height:550px;}
		p{margin-left:5px; font-size:14px;}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=fE4aCPUP3ByeIwvsUevgcgUQ5YcXh7dF"></script>
	<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
	<script type="text/javascript" src="js/jquery-2.2.3.min.js" ></script>
	<title>根据列表展示</title>
</head>
<body>
	<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
	// 百度地图API功能	
	map = new BMap.Map("allmap");
	map.centerAndZoom("成都", 10);
	map.enableScrollWheelZoom(true);
	//callMap(1);
	function callMap(){ 
		//alert("nihao");
		$.ajax({
			type:"get",
			url:"/map/stu/",
			async:true,
			success:function(data){
				var coord= new Array();
				for(var i=0;i<data.length;i++){
					coord[i]=new Array();
					coord[i][0]=data[i].userBean.uXcoordinate;
					coord[i][1]=data[i].userBean.uYcoordinate;
					coord[i][2]=data[i].userBean.uAddress;
					coord[i][3]=data[i].userBean.uName;
				}
				var data_info = coord; 
				
				 /* var data_info = [[104.075781,30.647372,"地址：四川大学（华西校区）","川大"],
								 [104.118891,30.674251,"地址：SM广场","SM"],
								 [104.072215,30.663504,"地址：天府广场","广场"]
								];  */
				/*var coordin= data_info;
				for(var i=0;i<data_info.length;i++){
					coordin[i]=new Array();
					for(var j=0;j<3;j++){
						coordin[i][j]=data_info[i][j];
				}
				}*/
				
				var opts = {
							width : 250,     // 信息窗口宽度
							height: 80,     // 信息窗口高度
							title : "地址信息" , // 信息窗口标题
							enableMessage:true//设置允许信息窗发送短息
						   };
				for(var i=0;i<data_info.length;i++){
					var marker = new BMap.Marker(new BMap.Point(data_info[i][0],data_info[i][1]));  // 创建标注
					var content = data_info[i][2];
					map.addOverlay(marker);               // 将标注添加到地图中
					addClickHandler(content,marker);
					var label = new window.BMap.Label(data_info[i][3], {
			                	offset : new window.BMap.Size(20, -10)
			                    });
			        marker.setLabel(label);//添加红框框
				}
				function addClickHandler(content,marker){
					marker.addEventListener("click",function(e){
						openInfo(content,e)}
					);
				}
				function openInfo(content,e){
					var p = e.target;
					var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
					var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象 
					map.openInfoWindow(infoWindow,point); //开启信息窗口
				}
			}
		});
	
	}  
	callMap();
	
</script>
